#include "RingBuffer.hpp"
#include <pthread.h>
#include <unistd.h>
using namespace RingBufferModule;
void *Consumer(void *argc)
{
    RingBuffer<int> *ring_buffer = (RingBuffer<int>*)argc;

    while (true)
    {
        // sleep(1);
        int data;
        ring_buffer->Pop(&data);
        cout << "消费了一个数据：" << data << endl;
    }
    
}
void *Product(void *argc)
{
    RingBuffer<int> *ring_buffer = (RingBuffer<int>*)argc;
    int data = 0;
    while (true)
    {
        // 1.获取数据
        sleep(1);

        // 2.生产数据
        ring_buffer->Equeue(data);
        cout << "生产了一个数据：" << data << endl; 
        data++;
    }
    
}
int main()
{
    RingBuffer<int> *ring_buffer = new RingBuffer<int>(5);
    pthread_t c1,c2,p1,p2;
    pthread_create(&c1,nullptr,Consumer,ring_buffer);
    pthread_create(&c2,nullptr,Consumer,ring_buffer);
    pthread_create(&p1,nullptr,Product,ring_buffer);
    pthread_create(&p2,nullptr,Product,ring_buffer);

    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);

    delete ring_buffer;
    return 0;
}